//
//  WBNaviController.swift
//  WeiBo
//
//  Created by 安中 on 2020/4/28.
//  Copyright © 2020 az. All rights reserved.
//

import UIKit

class WBNaviController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏默认的NavigationBar
//        navigationBar.isHidden = true
    }
    
    //viewController是被push的控制器，可以自定义左侧返回按钮
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //隐藏底部的tabbar
        //不是栈底的控制器才需要隐藏,根控制器不需要隐藏
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            //判断控制器类型  设置返回按钮
            if let vc = viewController as? WBBaseController {
                vc.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "blackBack"), style: .plain, target: self, action: #selector(backAction))
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    
    @objc private func backAction() {
        popViewController(animated: true)
    }
}
